function recoverUser(value) {
    $.post(
        "/user/recoverUser",
        {userId: value},
        function (response) {
            if (response.code == 0) {
                $('#StatusBtn' + value).removeClass("btn-warning")
                $('#StatusBtn' + value).addClass("btn-success")
                $('#StatusBtn' + value).attr("onclick", "deleteUser(" + value + ")")
                $('#StatusBtn' + value).text("正常")
            }
            alert(response.msg)
        })
}

function disableUser(value) {
    $.post(
        "/user/disableUser",
        {userId: value},
        function (response) {
            if (response.code == 0) {
                $('#StatusBtn' + value).removeClass("btn-success")
                $('#StatusBtn' + value).addClass("btn-warning")
                $('#StatusBtn' + value).attr("onclick", "recoverUser(" + value + ")")
                $('#StatusBtn' + value).text("停用")
            }
            alert(response.msg)
        })
}


//导入excel文件
$("#uploadUserBtn").on('click', function () {

    if (confirm("请使用Excel文件录入的新增账户:\n确保账号唯一，文件内容格式正确")) {
        if ($("#uploadUserFile").val().length <= 0) {
            alert("请选择文件");
            return false;
        } else {
            var filepath = $("#uploadUserFile").val();
            var extStart = filepath.lastIndexOf(".");
            var ext = filepath.substring(extStart, filepath.length).toUpperCase();
            if (ext != ".XLSX" && ext != ".XLS" && ext != ".XLSM") {
                alert("请上传excel格式文档");
                return false;
            }
        }
        var formData = new FormData();
        var deptId = $("#deptInput").val();
        formData.append("file", $("#uploadUserFile")[0].files[0]);
        formData.append("deptId", deptId);//这个地方可以传递多个参数
        $.ajax({
            url: "/user/createUser",
            type: 'POST',
            async: false,
            data: formData,
            // 告诉jQuery不要去处理发送的数据
            processData: false,
            // 告诉jQuery不要去设置Content-Type请求头
            contentType: false,
            beforeSend: function () {
                console.log("正在进行，请稍候");
            },
            success: function (response) {
                if (response.code == 0) {
                    if (response.data == null) {
                        alert(response.msg)
                    } else {
                        alert(response.msg + ":\n" + response.data);
                    }
                } else {
                    alert(response.msg);
                }
            }
        });
    }

});


function resetPassword(value) {
    if (confirm("您确认重制该账户密码?")) {
        $.post(
            "/user/resetPassword",
            {
                userId: value,
                password: null
            },
            function (response) {
                alert(response.msg)
            })
    }
}